package com.itheima.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.dubbo.dao.AnnouncementDao;
import com.itheima.model.domain.Announcement;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class AnnouncementApiImpl implements AnnouncementApi {
    @Autowired
    private AnnouncementDao announcementDao;

    @Override
    public Page announcements(Integer page, Integer pagesize) {
        //创建分页构造器
        Page pages = new Page<>(page, pagesize);
        LambdaQueryWrapper<Announcement> lqw = Wrappers.lambdaQuery(Announcement.class);
        lqw.orderByDesc(Announcement::getCreated).orderByAsc(Announcement::getUpdated);
        Page selectPage = announcementDao.selectPage(pages, lqw);
        return selectPage;
    }
}
